<template>
  <view class="phxx-item-detail">
    <!-- 销售接单 -->
    <view class="content-box" v-show="!showReadMe">
      <view class="title-item"> 基本信息 </view>
      <view class="bottom block-back">
        <view class="uni-form-item">
          <view class="title">客户名称</view>
          <input class="uni-input disab-box" disabled v-model="waybillData.waybillRespVO.cusName" />
        </view>
        <view class="uni-form-item">
          <view class="title">区域</view>
          <view class="uni-input disab-box">{{
            waybillData.waybillRespVO.provinceName +
            waybillData.waybillRespVO.cityName || ''
            }}</view>
        </view>
        <view class="uni-form-item">
          <view class="title">客户电话</view>
          <input class="uni-input disab-box" disabled v-model="waybillData.waybillRespVO.cusPhone" />
        </view>
        <view class="uni-form-item">
          <view class="title">联系人名称</view>
          <input class="uni-input disab-box" disabled v-model="waybillData.waybillRespVO.userName" />
        </view>
        <view class="uni-form-item">
          <view class="title">联系人电话</view>
          <input class="uni-input disab-box" disabled v-model="waybillData.waybillRespVO.userPhone" />
        </view>
      </view>
      <view class="title-item"> 司机信息 </view>
      <view class="bottom block-back">
        <view class="uni-form-item">
          <view class="title">姓名</view>
          <input class="uni-input disab-box" disabled v-model="waybillData.waybillRespVO.carName" />
        </view>
        <view class="uni-form-item">
          <view class="title">身份证号</view>
          <view class="uni-input disab-box">{{ driverCard }}</view>
        </view>
        <view class="uni-form-item">
          <view class="title">司机电话</view>
          <input class="uni-input disab-box" disabled v-model="waybillData.waybillRespVO.carPhone" />
        </view>

        <view class="uni-form-item">
          <view class="title"><span style="color: red">*</span>车牌号</view>
          <input class="uni-input disab-box" disabled :value="selectedCar" placeholder="请选择车辆" @click="open" />
        </view>

        <view class="uni-form-item">
          <view class="title"><span style="color: red">*</span>车辆类型</view>
          <view class="uni-select-box">
            <view class="uni-input" @click="showPop">{{
              cartypeValue || ''
              }}</view>
            <uni-icons type="forward" size="20"></uni-icons>
          </view>
          <uv-picker ref="selectBoxPop" :confirmColor="curColor" :columns="cartypeRange" keyName="text"
            @confirm="changeCartype"></uv-picker>
        </view>
      </view>

      <view class="btns">
        <button :class="{ loading: isLoading }" plain size="default" type="primary" @click="handleJieDan">
          接单{{
          !!payAmount && payAmount != 0 ? '（' + payAmount + '）元' : ''
          }}
          <view v-if="isLoading" class="loading-icon"></view>
        </button>
      </view>
    </view>
    <!-- 公告提示弹窗 -->
    <uni-popup ref="messShow" mode="center" width="300rpx" border-radius="20" :mask-close-able="false">
      <view class="tipsBox">
        <view class="tipsHeader"> 公告 </view>
        <view class="tipsDesc">
          {{ tipsMess }}
        </view>
        <view class="messBtn">
          <button class="btn" type="primary" @click="closeTipsWin()">
            确认
          </button>
        </view>
      </view>
    </uni-popup>
    <!-- 车辆选择弹窗 -->
    <uni-popup class="carPop" ref="popup">
      <view class="carList">
        <view class="top">
          <view class="title">
            选择车牌
            <view class="cph" @click="handleAddCar">
              <image :src="backImgAdd"></image>
            </view>
          </view>
        </view>
        <view class="a-i-c">
          <view v-for="(item, index) in vehicleLists" :key="index">
            <view class="item-box" :class="{ 'car-box': index == vehicleLists.length - 1 }" @click="handleCar(item)">
              <view class="cph">
                <image :src="carImg"></image>{{ item.vehicleNo }}
              </view>
              <view class="status">
                <text class="isReal" v-if="item.isIdentified">已认证</text>
                <text class="isnotReal" @click="recognizeCar(item)" v-else>未认证</text>
              </view>
            </view>
          </view>
        </view>
      </view>
    </uni-popup>
    <!-- 接单确认弹窗 -->
    <uni-popup class="linePaymentPop" ref="payConfirmDialog">
      <view class="payconfirmBox">
        <view class="main-box">
          <view class="top">
            <view @click="exit" class="close">X</view>
            <view class="title"></view>
            <view class="btn" @click="toChargeFun">充值</view>
          </view>
          <view class="content">
            <view class="money"> ￥{{ payAmount }}元 </view>
            <view class="showing">
              <view>付款方式</view>
              <view>钱包支付</view>
            </view>
          </view>
        </view>
        <view class="btn-box">
          <button :class="{ loading: isLoading }" class="agreeBtn" size="default" type="primary"
            @click="handleOrderPay">
            确认接单
            <view v-if="isLoading" class="loading-icon"></view>
          </button>
        </view>
      </view>
    </uni-popup>
    <!-- 阅读 -->
    <view v-if="showReadMe">
      <view class="back-meng"></view>
      <view class="phxx-itemss">
        <view class="header">
          <view class="title">《华业开泰运输管理协议》</view>
        </view>
        <view class="top">
          <view>司机考核要求，进入站台重车司机发生发现以下情形，视情况确认执行以下制度：</view>
          <view class="tit">
            1、进入集运站的大型运输车辆，车速不得超过 5
            公里/小时。超速者扣除运费 50 元造成事故移交公安机关处理。
          </view>
          <view class="tit">
            2、进入集运站的大型运输车辆，按照华业开泰相关规定扫
            码登记，未按照规定扫码，登记强行闯杆者给予扣除运费 100~300 元。
          </view>
          <view class="tit">
            3、大型运输车辆做好环保遮盖工作，在磅房前 20
            米指定区域揭开遮盖篷布后方可上磅，并积极配合工作人员查验煤质，不揭篷布、不配合查验煤质者，给予扣除运费100~500元;运输车辆环保工作不到位，致使运输货物抛洒路面，视其情节轻重给予扣除运费
            100~200 元。
          </view>
          <view class="tit"> 4、严禁洒水，一经发现罚款3000元。 </view>
        </view>
        <view class="btn">
          <view class="read">
            <view class="read-box" @click="handleChange">
              <image v-if="agree" :src="checkImg" style="width: 30rpx; height: 30rpx"></image>
              <image v-else :src="uncheckImg" style="width: 30rpx; height: 30rpx"></image>
            </view>
            我已阅读并同意
          </view>
          <button :class="{ 'not-read': !agree }" type="primary" @click="closeLinepop">
            同意
          </button>
        </view>
      </view>
    </view>
    <uni-popup class="jdcgPop" ref="jdcgPop" :mask-click="false">
      <view class="top">
        <view class="title-box">
          <view class="tit1">
            <image :src="imagesSuccess" class="logo" mode="widthFix"></image>
          </view>
          <view class="title">
            车辆<font style="color: #409efe">【{{ selectedCar }}】</font>接单成功！
          </view>
          <view v-if="isOtherTip" class="tit1"> 并已进入蓝色区域请尽快在小程序签到排号，<font style="color: red">未排号或未叫号车辆将无法入场</font>
          </view>
        </view>
        <view class="body">
          <view class="tit"> 温馨提示： </view>
          <view class="tit">
            <view class="icon">
              <view class="icon-inner"></view>
            </view>
            <view>请务必携带<font style="color: #FF4D4F">有效身份证</font>，否则会无法入场过磅。</view>
          </view>
          <view class="tit">
            <view class="icon">
              <view class="icon-inner"></view>
            </view>
            如需审核请及时联系货主审核运单。
          </view>
          <view v-if="isOtherTip" class="tit">
            <view class="icon">
              <view class="icon-inner"></view>
            </view>
            <font style="color: #409EFE">蓝色区域</font>为排队区域。
          </view>
          <view v-if="isOtherTip" class="tit">
            <view class="icon">
              <view class="icon-inner"></view>
            </view>
            <font style="color: #FF4D4F">红色区域</font>为禁停区域（未叫号禁止入内）。
          </view>
          <view v-if="isOtherTip" class="tit">
            <view class="icon">
              <view class="icon-inner"></view>
            </view>
            <font>
              收到叫号进场通知，请在规定时间入场，否则将自动作废。关注公众号【神煤交易智慧计量】及时获取信息！
            </font>
          </view>
        </view>
        <view class="btn" style="margin-top:120rpx">
          <button type="primary" plain size="default" :disabled="isCounting" :class="{ 'disabled-button': isCounting }"
            @click="confirmJieDan">
            {{ isCounting ? `确认 (${countdown}s)` : '确认' }}
          </button>
        </view>
      </view>
    </uni-popup>
    <tip-box :show="showBlacklistTip" :message="blacklistTip" :duration="8000" @showTip="showTip"></tip-box>
  </view>
</template>
<script>
  import func from '@/utils/funlogin.js';
  import { showMessageApi } from '@/api/system/goods.js';
  import {
    getWaybNbyTenantid,
    getWaybCost,
    payWaybillCost,
    getDriverMoney
  } from '@/api/system/waybill.js';
  import {
    getOpenId,
    getTenantId,
    getAccessToken,
    setWayBillNo,
    getDriverId
  } from '@/utils/auth';
  import {
    checkRuningCar,
    getWayBillDetail,
    addWaybillListsBJ,
    getLineUpDetail,
    getDetailByCodeFromBJ,
    getWayBillDetailLatest,
    getVehicle,
    getCarType,
    getTenantConfig,
    addWaybillLists,
    findDriverWaybill,
    findLineupSwitchByTenant
  } from '@/api/me.js';
  import { toast, getCurrenDate } from '@/utils/common';
  import config from '@/config';

  export default {
    data() {
      return {
        lineupSwitch: 1,
        payOriginalVal: undefined,
        cartypeValue: undefined,
        isJiedanRead: false,
        showReadMe: false,
        agree: false,
        tipsMess: '',
        isLoading: false,
        payAmount: 0,
        payCostFlag: false,
        driverCard: '',
        selectedCar: undefined,
        vehicleLists: [],
        cartypeRange: [],
        driverInfos: {
          cusName: undefined
        },
        showBlacklistTip: false,
        blacklistTip: '',
        waybillData: {
          waybillRespVO: {
            orderCost: undefined,
            cusName: undefined,
            relId: undefined,
            cusId: undefined,
            userId: undefined,
            carName: undefined,
            carCard: undefined,
            carBrand: undefined,
            modelId: undefined,
            carPhone: undefined,
            wxId: undefined,
            cusTransport: undefined,
            planNo: undefined,
            driverId: undefined,
            enterId: undefined,
            transportPlanId: undefined,
            waybillNo: undefined,
            planType: undefined
          },
          hours: 0,
          minutes: 0,
          currentLineupCount: 0,
          enableStatus: undefined
        },
        isCounting: false,
        countdown: 5,
        isOtherTip: false
      };
    },
    methods: {
      handleChange() {
        this.agree = !this.agree;
      },
      closeLinepop() {
        if (!this.agree) return;
        this.showReadMe = false;
      },
      showPop() {
        this.$refs['selectBoxPop'].open('bottom');
      },
      closeTipsWin() {
        this.$refs['messShow'].close();
      },
      changeCartype(e) {
        if (this.cartypeRange.length > 0) {
          this.cartypeValue = e.value[0].text;
          uni.setStorageSync('cartypeData', this.cartypeValue);
          this.waybillData.waybillRespVO.modelId = e.value[0].text;
          uni.setStorageSync('cartypeDataId', e.value[0].text);
        }
      },
      inputWeight(e) {
        if (e.detail.value < 0.01 || e.detail.value > 100) {
          toast('矿发净重输入范围0.01到100');
        }
      },
      recognizeCar(item) {
        uni.setStorageSync('isSetSjxx', 'bj');
        this.$tab.reLaunch(
          `/packageB/pages/common/vehicle-editing/vehicle-editing?id=${item.id}`
        );
      },
      exit() {
        this.$refs.payConfirmDialog.close();
      },
      //接单生成运单
      async handleJieDan() {
        console.log('接单啦');
        let _ = this;
        this.waybillData.waybillRespVO.carBrand = this.selectedCar;

        //校验参数
        if (!_.waybillData.waybillRespVO.carBrand) {
          toast(`请选择车辆`);
          return;
        }
        if (!_.waybillData.waybillRespVO.modelId) {
          toast(`请选择车辆类型`);
          return;
        }
        const validWaybill = await this.findDriverWaybill();
        if (!validWaybill.purchaseStatus) {
          toast(validWaybill.purchaseMessage);
          return;
        }
        if (!validWaybill.saleStatus) {
          toast(validWaybill.saleMessage);
          return;
        }
        //TODO 接单页面验证通过，再验证钱包余额（如果需要接单费用）
        if (this.payAmount > 0) {
          //弹出接单支付确认框
          this.$refs['payConfirmDialog'].open('bottom');
        } else {
          this.handleOrderNoPay();
        }
      },
      async findDriverWaybill() {
        const data = {
          vehicleNo: this.selectedCar,
          driverIdCard: this.waybillData.waybillRespVO.carCard,
          enterId: getTenantId()
        };
        const res = await findDriverWaybill(data);
        if (res.code === '200') {
          return res?.data;
        }
        return {
          saleStatus: false,
          saleMessage: res.msg
        };
      },
      async handleOrderNoPay() {
        if (this.isLoading) return;
        this.isLoading = true;
        //无费用直接接单
        let _ = this;
        let driverMoney = await getDriverMoney();
        if (driverMoney.code == 0) {
          if (Number(driverMoney.data.balance / 100) < this.payAmount) {
            //2.余额不够，跳转到充值界面
            toast('钱包余额不足，请充值');
          } else {
            //1.余额足够：直接接单
            _.waybillData.waybillRespVO.orderCost = this.payAmount * 100
            _.waybillData.waybillRespVO.enterId = getTenantId();
            _.waybillData.waybillRespVO.userId = uni.getStorageSync('curUserId');
            _.waybillData.waybillRespVO.driverId = uni.getStorageSync('sjxxData').id;
            _.waybillData.waybillRespVO.wxId = getOpenId();
            _.waybillData.waybillRespVO.cusTransport = '';
            _.waybillData.waybillRespVO.planNo =
              uni.getStorageSync('ysjhData').planId;

            try {
              let res = await addWaybillListsBJ(_.waybillData.waybillRespVO);
              if (res.code == '200') {
                this.isOtherTip = this.lineupSwitch === 0 ? true : false
                this.$refs['jdcgPop'].open('bottom');
                this.startCountdown()
                // this.linkToPage();
              } else if (res.code === '12000') {
                this.blacklistTip = res.msg;
                this.showBlacklistTip = true;
              } else {
                this.blacklistTip = res.msg;
                this.showBlacklistTip = true;
              }
            } catch (e) {
              this.isLoading = false;
              return false;
            }
            this.isLoading = false;
            this.removeStorageDatas();
          }
        }
      },
      async handleOrderPay() {
        try {
          let _ = this;
          if (this.isLoading) return;
          this.isLoading = true;
          let driverMoney = await getDriverMoney();
          if (driverMoney.code == 0) {
            if (Number(driverMoney.data.balance / 100) < this.payAmount) {
              //2.余额不够，跳转到充值界面
              toast('钱包余额不足，请充值');
            } else {
              //1.余额足够：直接接单
              _.waybillData.waybillRespVO.orderCost = this.payAmount * 100
              _.waybillData.waybillRespVO.enterId = getTenantId();
              _.waybillData.waybillRespVO.userId =
                uni.getStorageSync('curUserId');
              _.waybillData.waybillRespVO.driverId =
                uni.getStorageSync('sjxxData').id;
              _.waybillData.waybillRespVO.wxId = getOpenId();
              _.waybillData.waybillRespVO.cusTransport = '';
              _.waybillData.waybillRespVO.planNo =
                uni.getStorageSync('ysjhData').planId;
              const res = await addWaybillListsBJ(
                _.waybillData.waybillRespVO
              );
              if (res.code == '200') {
                // this.linkToPage();
                this.exit()
                this.isOtherTip = this.lineupSwitch === 0 ? true : false
                this.$refs['jdcgPop'].open('bottom');
                this.startCountdown()
              } else if (res.code === '12000') {
                this.blacklistTip = res.msg;
                this.showBlacklistTip = true;
              } else if (res.code === '100') {
                this.blacklistTip = res.msg;
                this.showBlacklistTip = true;
              } else {
                this.blacklistTip = res.msg;
                this.showBlacklistTip = true;
                this.payAmount = 0;
                this.getLatestWayBill();
              }
              this.removeStorageDatas();
              // const data = await getWaybNbyTenantid(
              //   getDriverId(),
              //   uni.getStorageSync('ysjhData').tenantId,
              //   this.waybillData.waybillRespVO.planType
              // );
              // if (data.code == 200) {
              //   this.waybillData.waybillRespVO.waybillNo = data.data.waybillNo;
              //   setWayBillNo(this.waybillData.waybillRespVO.waybillNo);
              //   let resBalance = await payWaybillCost({
              //     waybillNo: this.waybillData.waybillRespVO.waybillNo,
              //     orderCost: Number(this.payAmount) * 100,
              //     queueType: 2
              //   });
              //   if (resBalance.code == 0) {
              //     //支付成功后创建一个接单
              //     this.waybillData.waybillRespVO.orderCost = this.payOriginalVal
              //     _.waybillData.waybillRespVO.enterId = getTenantId();
              //     _.waybillData.waybillRespVO.userId =
              //       uni.getStorageSync('curUserId');
              //     _.waybillData.waybillRespVO.driverId =
              //       uni.getStorageSync('sjxxData').id;
              //     _.waybillData.waybillRespVO.wxId = getOpenId();
              //     _.waybillData.waybillRespVO.cusTransport = '';
              //     _.waybillData.waybillRespVO.planNo =
              //       uni.getStorageSync('ysjhData').planId;
              //     const res = await addWaybillListsBJ(
              //       _.waybillData.waybillRespVO
              //     );
              //     if (res.code == '200') {
              //       this.linkToPage();
              //       this.exit()
              //     } else if (res.code === '12000') {
              //       this.blacklistTip = res.msg;
              //       this.showBlacklistTip = true;
              //     } else {
              //       this.blacklistTip = res.msg;
              //       this.showBlacklistTip = true;
              //       this.payAmount = 0;
              //       this.getLatestWayBill();
              //     }
              //     this.removeStorageDatas();
              //   } else {
              //     toast(resBalance.msg);
              //   }
              // }
            }
          }
        } finally {
          setTimeout(() => {
            this.isLoading = false;
          }, 1000)
        }
      },
      confirmJieDan() {
        if (this.isCounting) return;
        this.$refs['jdcgPop'].close();
        this.linkToPage();
      },
      linkToPage() {
        if (this.lineupSwitch === 0) {
          uni.setStorageSync('orderType', 2);
          this.$tab.reLaunch(`/pages/index?carno=${this.selectedCar}`);
          return;
        }
        if (this.waybillData.waybillRespVO.planType == 1) {
          this.$tab.reLaunch('/pages/waybill?type=pull');
        } else {
          uni.setStorageSync('orderType', 2);
          this.$tab.reLaunch('/pages/waybill?type=pull');
        }
      },
      async findLineupSwitchByTenant() {
        const res = await findLineupSwitchByTenant(getTenantId());
        if (res.code === '200') {
          this.lineupSwitch = res.data?.saleLineupSwitch;
        }
      },
      handleAddCar() {
        uni.setStorageSync('isSetSjxx', 'bj');
        uni.navigateTo({
          url: '/packageB/pages/common/vehicle-editing/vehicle-authentica?type=code'
        });
      },
      async handleCar(item) {
        //先去校验该车辆是否有正在执行中的运单
        let res = await checkRuningCar({
          vehicleNo: item.vehicleNo,
          enterId: getTenantId()
        });
        if (res.code != '200') {
          toast(`${res.msg}`);
          return;
        }
        this.selectedCar = item.vehicleNo;
        uni.setStorageSync('vehicleNoByCode', item.vehicleNo);
        this.waybillData.waybillRespVO.carBrand = item.vehicleNo;
        this.$refs['popup'].close();
      },
      setStorageDatas() {
        let _ = this;
        uni.setStorageSync('netweightByCode', _.netWeight);
        uni.setStorageSync('datetimeJiedanByCode', _.datetimesingle);
        uni.setStorageSync(
          'vehicleNoByCode',
          _.waybillData.waybillRespVO.carBrand
        );
        uni.setStorageSync(
          'loadingWeighbridgeByCode',
          _.waybillData.waybillRespVO.uuid
        );
        uni.setStorageSync(
          'cardbankByCode',
          _.waybillData.waybillRespVO.freightCollectionAccount
        );
      },
      removeStorageDatas() {
        uni.removeStorageSync('isSetSjxx');
        uni.removeStorageSync('cartypeData');
        uni.removeStorageSync('cartypeDataId');
        uni.removeStorageSync('salePayNum');
      },
      // 获取司机最新运单详情
      async getLatestWayBill() {
        try {
          const res = await getWayBillDetailLatest({
            "tenant-id": getTenantId(),
            "Authorization": 'Bearer ' + getAccessToken(),
          }, { businessType: 2 });
          if (res.code == 0) {
            const status = res.data?.waybillStatus;
            if (status == 1 && this.lineupSwitch == 0) {
              uni.setStorageSync('orderType', 2);
              const id = res.data.waybillNo
              if (id) {
                this.$tab.reLaunch(`/pages/index?codes=true&id=${id}`);
              }
              return
            }
            if (status == 1 && this.lineupSwitch == 1) {
              uni.setStorageSync('orderType', 2);
              this.$tab.reLaunch(`/pages/waybill?type=pull`);
              return
            }
            if ([0, 2, 3, 4, 5].includes(status)) {
              uni.setStorageSync('orderType', 2);
              this.$tab.reLaunch(`/pages/waybill?type=pull`);
              return
            }
            this.isJiedanRead = true;
            this.getTransPlanData(uni.getStorageSync('ysjhData').planId);
          } else {
            toast(res.msg);
          }
        } catch (e) {
          return false;
        }
      },
      //获取车辆列表
      async getCarList() {
        try {
          //遍历对象过滤空值
          let data = {
            pageNo: 1,
            pageSize: 100
          };
          let res = await getVehicle(data);
          if (res.code == 0) {
            this.vehicleLists = res.data.list;
          }
        } catch (e) {
          return false;
        }
      },
      //获取车辆列表
      async getCarTypeList() {
        try {
          //遍历对象过滤空值
          let data = {
            enterId: getTenantId()
          };
          let res = await getCarType(data);
          if (res.code == '200') {
            this.cartypeRange = [];
            if (res.data.length > 0) {
              this.cartypeRange = [
                res.data.map((item) => {
                  return {
                    value: item.id,
                    text: item.modelName
                  };
                })
              ];
            }
          }
        } catch (e) {
          return false;
        }
      },
      resetWaybillData() {
        this.waybillData = {
          waybillRespVO: {
            cusName: undefined,
            relId: undefined,
            cusId: undefined,
            userId: undefined,
            carName: undefined,
            carCard: undefined,
            carBrand: undefined,
            modelId: undefined,
            carPhone: undefined,
            wxId: undefined,
            cusTransport: undefined,
            planNo: undefined,
            driverId: undefined,
            enterId: undefined,
            transportPlanId: undefined,
            planType: undefined
          },
          hours: 0,
          minutes: 0,
          currentLineupCount: 0,
          enableStatus: undefined
        };
      },
      async getTransPlanData(id) {
        let _ = this;
        _.getCarList();
        _.resetWaybillData();
        try {
          let res = await getDetailByCodeFromBJ({
            planNo: id,
            isOperation: uni.getStorageSync('ysjhData').isOperation
          });
          if (res.code == '200') {
            //展示公告
            let messData = await showMessageApi({
              enterId: getTenantId(),
              mesStatus: 0 //司机端固定传0
            });
            if (messData.code == '200') {
              if (!!messData.data.mesInfo) {
                this.tipsMess = messData.data.mesInfo;
                this.$refs['messShow'].open();
              }
            }
            if (res.data.planType == 2) {
              let resCost = await getWaybCost({
                planType: res.data.planType,
                customerOrPurchaserId: res.data.cusId
              });
              if (resCost.code == 0) {
                _.payOriginalVal = resCost.data
                if (resCost.data !== 0 && resCost.data !== null) {
                  _.payAmount = parseFloat(resCost.data / 100).toFixed(2)
                }
              }
              //"销售"
              //TODO 获取运单编号
              // let data = await getWaybNbyTenantid(
              //   getDriverId(),
              //   uni.getStorageSync('ysjhData').tenantId,
              //   res.data.planType
              // );
              // if (data.code == 200) {
              //   _.waybillData.waybillRespVO.waybillNo = data.data.waybillNo;
              //   setWayBillNo(this.waybillData.waybillRespVO.waybillNo);
              //   _.payCostFlag = data.data.tradeStatus;
              //   if (data.data.tradeStatus) {
              //     //TODO 获取费用配置
              //     let resCost = await getWaybCost({
              //       planType: res.data.planType,
              //       customerOrPurchaserId: res.data.cusId
              //     });
              //     if (resCost.code == 0) {
              //       _.payAmount = parseFloat(resCost.data / 100).toFixed(2);
              //     }
              //   }
              // }
            }
            let driverInfo = uni.getStorageSync('sjxxData');
            console.log(driverInfo, 'driverInfo====');
            uni.removeStorageSync('currentLinePageData');
            uni.setStorageSync('driverInfoData', driverInfo);
            uni.setStorageSync('currentLinePageData', res.data);
            uni.setStorageSync('curUserId', res.data.userId);
            _.waybillData.waybillRespVO.transportPlanId = res.data.id;
            _.waybillData.waybillRespVO.cusName = res.data.cusName;
            _.waybillData.waybillRespVO.userId = res.data.userId;
            _.waybillData.waybillRespVO.provinceName = res.data.provinceName;
            _.waybillData.waybillRespVO.cityName = res.data.cityName;
            _.waybillData.waybillRespVO.cusPhone = res.data.cusPhone;
            _.waybillData.waybillRespVO.userName = res.data.userName;
            _.waybillData.waybillRespVO.userPhone = res.data.userPhone;
            _.waybillData.waybillRespVO.planType = res.data.planType;
            _.waybillData.waybillRespVO.carName = driverInfo.driverName;
            _.waybillData.waybillRespVO.carCard = driverInfo.idNo;
            _.driverCard =
              driverInfo.idNo.slice(0, 3) + '****' + driverInfo.idNo.slice(-3);
            _.waybillData.waybillRespVO.carPhone = driverInfo.mobile;
            _.waybillData.waybillRespVO.cusId = res.data.cusId;
            _.waybillData.waybillRespVO.driverId = _.driverInfo.id;
            if (_.isJiedanRead && res.data.purchaserId == 6) {
              _.showReadMe = true;
            }
          } else {
            toast(res.msg)
          }
        } catch (e) {
          return false;
        }
      },
      toChargeFun() {
        uni.setStorageSync('isSetSjxx', 'bj')
        uni.setStorageSync('salePayNum', this.payAmount);
        this.$tab.navigateTo(
          '/packageB/pages/mine/my-wallet/recharge?types=code'
        );
      },
      open() {
        this.$refs['popup'].open('bottom');
      },
      showPageFromStorage() {
        let _ = this;
        let data = uni.getStorageSync('currentLinePageData');
        let driverData = uni.getStorageSync('driverInfoData');
        console.log('直接从缓存拿接单详情数据============================', data);
        _.getCarList(); //再次获取车辆
        let driverInfo = uni.getStorageSync('sjxxData');
        this.cartypeValue = uni.getStorageSync('cartypeData');
        this.payAmount = uni.getStorageSync('salePayNum');
        _.waybillData.waybillRespVO.userId = uni.getStorageSync('curUserId');
        _.waybillData.waybillRespVO.transportPlanId = data.id;
        _.waybillData.waybillRespVO.cusName = data.cusName;
        // _.waybillData.waybillRespVO.waybillNo = getWayBillNo();
        _.waybillData.waybillRespVO.provinceName = data.provinceName;
        _.waybillData.waybillRespVO.cityName = data.cityName;
        _.waybillData.waybillRespVO.cusPhone = data.cusPhone;
        _.waybillData.waybillRespVO.userName = data.userName;
        _.waybillData.waybillRespVO.modelId = uni.getStorageSync('cartypeDataId');
        _.waybillData.waybillRespVO.userPhone = data.userPhone;
        _.waybillData.waybillRespVO.carName = driverInfo.driverName;
        _.waybillData.waybillRespVO.carCard = driverInfo.idNo;
        _.driverCard =
          driverInfo.idNo.slice(0, 3) + '****' + driverInfo.idNo.slice(-3);
        _.waybillData.waybillRespVO.carPhone = driverInfo.mobile;
        _.waybillData.waybillRespVO.cusId = data.cusId;
        _.waybillData.waybillRespVO.driverId = driverInfo.id;

        _.selectedCar = uni.getStorageSync('vehicleNoByCode');
        _.waybillData.waybillRespVO.carBrand =
          uni.getStorageSync('vehicleNoByCode');
      },
      showTip(event) {
        this.showBlacklistTip = event;
      },
      startCountdown() {
        const hasCountdown = uni.getStorageSync('hasCountdown');
        if (!hasCountdown) {
          this.isCounting = true;
          const timer = setInterval(() => {
            if (this.countdown > 0) {
              this.countdown--;
            } else {
              this.isCounting = false;
              clearInterval(timer);
              // 倒计时结束后，设置标记
              uni.setStorageSync('hasCountdown', true);
            }
          }, 1000);
        }
      }
    },
    async onLoad(options) {
      await this.findLineupSwitchByTenant();
      this.planId = uni.getStorageSync('ysjhData').planId;
      this.getCarList();
      this.getCarTypeList();

      if (options?.codes) {
        let datas = uni.getStorageSync('ysjhData');
        if (options?.codes == 'czback') {
          //获取到缓存数据
          this.showPageFromStorage();
          return;
        }
        if (datas?.planId) {
          this.getLatestWayBill();
          return;
        }
        return;
      }
      if (uni.getStorageSync('isSetSjxx')) {
        this.showPageFromStorage();
      }
    },
    computed: {
      imagesSuccess() {
        if (this.$store.state.user.curTypeColor == '#D22C2C') {
          return config.baseImgUrl + '/sucess1.png';
        } else if (this.$store.state.user.curTypeColor == '#409EFE') {
          return config.baseImgUrl + '/sucess.png';
        } else {
        }
      },
      checkImg() {
        if (this.$store.state.user.curTypeColor == '#D22C2C') {
          return config.baseImgUrl + '/checked1.png';
        } else if (this.$store.state.user.curTypeColor == '#409EFE') {
          return config.baseImgUrl + '/checked.png';
        } else {
          return config.baseImgUrl + '/checked.png';
        }
      },
      uncheckImg() {
        return config.baseImgUrl + '/unchecked.png';
      },
      curColor() {
        return this.$store.state.user.curTypeColor;
      },
      carImg() {
        if (this.$store.state.user.curTypeColor == '#D22C2C') {
          return config.baseImgUrl + '/car1.png';
        } else if (this.$store.state.user.curTypeColor == '#409EFE') {
          return config.baseImgUrl + '/car.png';
        } else {
          return config.baseImgUrl + '/car.png';
        }
      },
      backImgAdd() {
        if (this.$store.state.user.curTypeColor == '#D22C2C') {
          return config.baseImgUrl + '/add1.png';
        } else if (this.$store.state.user.curTypeColor == '#409EFE') {
          return config.baseImgUrl + '/add.png';
        } else {
        }
      }
    },
    onShow() {
      console.log('receiving页面进入onShow');
    },
    onHide() { }
  };
</script>

<style lang="scss" scoped>
  ::v-deep.carPop,
  .cardPop {
    background-color: #fff;
    width: 750rpx;
    height: 522rpx;

    .carList {
      border-radius: 10rpx;
      padding: 10rpx;
      background-color: #fff;
      width: 750rpx;
      height: 522rpx;
      overflow: auto;
      font-size: 14px;

      .top {
        padding: 14rpx 16rpx;
        height: 56px;
        line-height: 63rpx;
        font-size: 15px;
        color: #000;
        font-weight: bold;
        border-bottom: 1px solid #e6e6e6;
        background: #fff;
        width: 98%;
        marin: 0;
        text-align: center;
      }

      .add-box {
        position: fixed;
        bottom: 59rpx;
        background: #fff;
        display: flex;
        justify-content: space-between;
        width: 97%;
        height: 102rpx;
        line-height: 73rpx;
        padding: 20rpx;

        .cph:last-child {
          float: right;
        }

        .cph:first-child {
          text-indent: 10rpx;

          image {
            width: 60rpx;
            height: 60rpx;
            float: left;
          }
        }
      }

      .a-i-c {
        position: relative;
        max-height: 398rpx;
        overflow: scroll;

        .car-box {
          margin-bottom: 102rpx;
        }

        .item-box {
          height: 60rpx;
          line-height: 60rpx;
          box-sizing: content-box;
          padding: 20rpx;
          font-size: 15px;
          border-bottom: 1px solid #ccc;
          display: flex;
          justify-content: space-between;

          .cph {
            font-weight: bold;
            text-indent: 10rpx;

            image {
              width: 60rpx;
              height: 60rpx;
              float: left;
            }
          }

          .isReal {
            color: #fff;
            padding: 10rpx;
            background-color: #19be6b;
            border-radius: 6rpx;
            line-height: 50rpx;
          }

          .isnotReal {
            color: #fff;
            padding: 10rpx;
            background-color: #f56c6c;
            border-radius: 6rpx;
            line-height: 50rpx;
          }

          .goReal {
            color: #fff;
            margin-left: 40rpx;
            padding: 10rpx;
            background-color: #1890ff;
            border-radius: 6rpx;
            line-height: 50rpx;
          }
        }
      }
    }
  }

  .loading {
    position: relative;
  }

  .back-meng {
    background: rgba(0, 0, 0, 0.6);
    position: absolute;
    top: 0;
    z-index: 8;
    left: 0;
    width: 100%;
    height: 100%;
  }

  .phxx-itemss {
    box-sizing: border-box;
    background: #fff;
    border-radius: 30rpx;
    width: 90vw;
    position: absolute;
    top: 12%;
    z-index: 9;
    left: 5vw;

    .header {
      width: 100%;
      height: 96rpx;
      line-height: 96rpx;
      border-bottom: 2rpx solid #eaeaea;
      text-align: center;
      color: #000;
      font-size: 16px;
      font-weight: 600;
    }

    .top {
      padding: 30rpx;
      font-size: 15px;

      .tit {
        margin-bottom: 20rpx;
      }
    }

    .btn {
      padding: 11rpx;

      button.not-read {
        background: #ccc !important;
      }
    }
  }

  .loading-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    position: absolute;
    top: 29%;
    left: 36%;
    transform: translate(-50%, -50%);
  }

  ::v-deep.jdcgPop {
    background-color: #fff;
    width: 750rpx;
    height: 450rpx;

    .top {
      background-color: #fff;
      width: 750rpx;
      font-size: 14px;
      padding: 20rpx;

      .title-box {
        border-bottom: 1px dashed #ccc;
        padding-bottom: 20rpx;
        text-align: center;
        font-size: 18px;
        color: #000;
        font-weight: bold;

        .tit {
          padding: 15rpx 0;
        }

        .tit1 {
          image {
            width: 218rpx;
            height: 188rpx;
          }
        }
      }

      .body {
        font-size: 30rpx;
        color: #666;
        padding: 20rpx 24rpx 0 24rpx;

        .tit {
          margin-bottom: 20rpx;
          display: flex;
          align-items: center;

          .icon {
            width: 16rpx;
            height: 16rpx;
            min-width: 16rpx;
            background: rgba(64, 158, 254, 0.5);
            display: inline-block;
            border-radius: 50%;
            position: relative;
            margin-right: 10rpx;

            .icon-inner {
              position: relative;
              background-color: #409efe;
              width: 8rpx;
              height: 8rpx;
              border-radius: 50%;
              top: 2px;
              left: 5rpx;
            }
          }
        }
      }
    }
  }

  @keyframes spin {
    0% {
      transform: rotate(0deg);
    }

    100% {
      transform: rotate(360deg);
    }
  }
</style>